<template>
  <div ref="container">
    <breadcrumb :breadList="breadList" :name="name">
      <div class="handle-box" slot="handleContent">
        <div class="handle-btn">
          <a-button class="common-btn" @click="go_toOperation('create', '')">新增阀值</a-button>
        </div>
        <div class="handle-btn">
          <a-button class="common-btn" @click="exportList">导出列表</a-button>
        </div>
      </div>
    </breadcrumb>
    <a-card>
      <a-form @submit="handleSubmit" :form="form">
        <a-row :gutter="16">
          <a-col :lg="24" :md="12" :sm="24">
            <div>
              <a-form-item class="spec-item" label="行政区域" :labelCol="{lg: {span: 2}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
                <div style="display:flex;">
                  <a-form-item>
                    <a-select v-decorator="['queryParam.provice', {initialValue: '山西省', rules: [{required: false, message: ''}]}]" style="width: 145px;">
                      <a-select-option value="山西省">山西省</a-select-option>
                      <a-select-option value="山东省">山东省</a-select-option>
                    </a-select>
                  </a-form-item>
                  <a-form-item>
                    <a-select v-decorator="['queryParam.municipal', {initialValue: '太原市', rules: [{required: false, message: ''}]}]" style="width: 145px;">
                      <a-select-option value="市">市</a-select-option>
                      <a-select-option value="太原市">太原市</a-select-option>
                      <a-select-option value="未知市">未知市</a-select-option>
                    </a-select>
                  </a-form-item>
                  <a-form-item>
                    <a-select v-decorator="['queryParam.county', {initialValue: '小店区', rules: [{required: false, message: ''}]}]" style="width: 145px;">
                      <a-select-option value="县（区）">县（区）</a-select-option>
                      <a-select-option value="小店区">小店区</a-select-option>
                      <a-select-option value="未知区">未知区</a-select-option>
                    </a-select>
                  </a-form-item>
                  <a-form-item>
                    <a-select v-decorator="['queryParam.village', {initialValue: '小店乡', rules: [{required: false, message: ''}]}]" style="width: 145px;">
                      <a-select-option value="乡（镇/街道）">乡（镇/街道）</a-select-option>
                      <a-select-option value="小店乡">小店乡</a-select-option>
                    </a-select>
                  </a-form-item>
                  <a-form-item>
                    <a-select v-decorator="['queryParam.burg', {initialValue: '小店村', rules: [{required: false, message: ''}]}]" style="width: 145px;">
                      <a-select-option value="村（社区）">村（社区）</a-select-option>
                      <a-select-option value="村">村</a-select-option>
                    </a-select>
                  </a-form-item>
                </div>
              </a-form-item>
            </div>
          </a-col>
        </a-row>
        <a-row clss="form-row" :gutter="16">
          <a-col :lg="8" :md="12" :sm="24">
            <a-form-item label="品牌" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 14}, sm: {span: 17} }">
              <a-input v-model="queryParam.proCode" placeholder="品牌" style="width: 240px;"/>
            </a-form-item>
          </a-col>
          <a-col :lg="8" :md="12" :sm="24">
            <a-form-item label="设备类型" :labelCol="{lg: {span: 10}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-select v-decorator="['queryParam.type', {initialValue: '1', rules: [{required: false, message: ''}]}]" style="width: 240px;">
                <a-select-option value="1">煤改气</a-select-option>
                <a-select-option value="2">煤改电</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="2" :md="12" :sm="24" :offset="2">
            <a-form-item label="" :colon="false">
              <a-button class="common-btn" @click="toSearch('2')">查询</a-button>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-card>
    <a-card>
      <a-table
        :columns="columns"
        :dataSource="loadData"
        bordered
        :loading="loading"
        :pagination="false">
        <template slot="operation" slot-scope="text, record">
          <p style="display:inline" @click="go_toOperation('modify',record)">
            <a href="javascript:;">编辑</a>
            <a-divider type="vertical"/>
          </p>
          <p style="display:inline">
            <a-popconfirm title="是否要删除此条数据么？" @confirm="remove(record.key)">
              <a>删除</a>
            </a-popconfirm>
          </p>
        </template>
      </a-table>
    </a-card>
  </div>
</template>

<script>
import Breadcrumb from '@/components/tools/Breadcrumb'
// import { getSupplierList } from '@/api/mockdata'
export default {
  name: 'SupplierManagementList',
  components: {
    Breadcrumb
  },
  data () {
    return {
      name: '',
      breadList: [],
      loading: false,
      form: this.$form.createForm(this),
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: '行政区域',
          width: '15%',
          dataIndex: 'eara'
        }, {
          title: '品牌',
          width: '10%',
          dataIndex: 'brand'
        }, {
          title: '设备类型',
          width: '10%',
          dataIndex: 'type'
        }, {
          title: '供水温度高限',
          width: '15%',
          dataIndex: 'highLimt'
        }, {
          title: '回水温度高限',
          width: '15%',
          dataIndex: 'lowLimt'
        },
        {
          title: '耗电/气量高限',
          width: '20%',
          dataIndex: 'totalLimt'
        },
        {
          title: '操作',
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: []
    }
  },
  created () {
    this.loading = true
    this.getBreadCrumb()
    setTimeout(() => {
      this.getData('1')
    }, 1000)
  },
  methods: {
    // 面包屑处理
    getBreadCrumb () {
      this.breadList = []
      this.name = this.$route.name
      this.$route.matched.forEach(item => {
        console.log('1111', item)
        this.breadList.push(item)
      })
    },
    getData (code) {
      const data = [
        {
          key: 1,
          eara: '山西省-太原市-小店区',
          brand: '美的1',
          type: '煤改气',
          highLimt: '30',
          lowLimt: '20',
          totalLimt: '999999999'
        }, {
          key: 2,
          eara: '山西省-太原市-小店区',
          brand: '美的2',
          type: '煤改气',
          highLimt: '30',
          lowLimt: '20',
          totalLimt: '999999999'
        }, {
          key: 3,
          eara: '山西省-太原市-小店区',
          brand: '美的3',
          type: '煤改气',
          highLimt: '30',
          lowLimt: '20',
          totalLimt: '999999999'
        }, {
          key: 4,
          eara: '山西省-太原市-小店区',
          brand: '美的4',
          type: '煤改气',
          highLimt: '30',
          lowLimt: '20',
          totalLimt: '999999999'
        }, {
          key: 5,
          eara: '山西省-太原市-小店区',
          brand: '美的5',
          type: '煤改气',
          highLimt: '30',
          lowLimt: '20',
          totalLimt: '999999999'
        }, {
          key: 6,
          eara: '山西省-太原市-小店区',
          brand: '美的6',
          type: '煤改气',
          highLimt: '30',
          lowLimt: '20',
          totalLimt: '999999999'
        }
      ]
      if (code === '1') {
        this.loadData = data
        setTimeout(() => {
          this.loading = false
        }, 1000)
      } else {
        this.loadData = data
        setTimeout(() => {
          this.loading = false
          this.$success({
            title: '查询成功'
          })
        }, 1000)
      }
    },
    toSearch (status) {
      this.loading = true
      this.getData(status)
    },
    handleSubmit () {
      console.log('ttt')
    },
    remove (key) {
      const newData = this.loadData.filter(item => item.key !== key)
      this.loadData = newData
    },
    exportList () {
      this.$success({
        title: '导出成功'
      })
    },
    go_toOperation (type, record) {
      console.log('========', record)
      this.$router.push({
        name: 'addThreshold',
        query: {
          type: type,
          proDetails: JSON.stringify(record)
        }
      })
    }
  }
}

</script>

<style lang="less" scoped>
.spec-item {
  margin-bottom: 12px;
}
</style>
